var foundSeven = {};
function hasSevenTrhths(obj)
{
	var counted = 0;
	function count(obj)
	{
		for(var name in obj)
		{
			if(obj[name] == true)
			{
				counted++;
				if(counted == 7)
				{
					throw FoundedSeven;			
				}
			}
			else if(typeof obj[name] == "object")
			{
				count(obj[name]);
			}
		}
	}
}

try {
	count(object);
}
catch (exception){
	if(exception != FoundSeven)
	{
		throw exception;
	}
	return true;
}

	
try {
	throw new Error("Fire!");
}

catch(error)
{
	document.write(error.message);
}
	

var currentThing = null;
function processThing(thing)
{
	if(currentThing != null)
		throw "we are already processing a thing";
	currentThing = thing;
	
	try {
	// do complicated processing
	}
	
	finally {
		currentThing = null;
	}
}


function lastElement(array)
{
	if(array.length > 0)
		return array[array.length-1];
	else
		throw "Can not take the last element of an empty array.";
}

function lastElementPlusTen(array)
{
	return lastElement(array) + 10;
}

try {
	alert(lasetElemtnPlusTen([]));
}

catch (error)
{
//	document.write("something went wrong.\n");
//	document.write(error.message);
}

		
while(0)
{
	var input = prompt("tell me something");
	if(input == 'q')
		break;
	var parenthesized = between(input, "(", ")");
	if(parenthesized != undefined)
	{
		alert(parenthesized);
	}	
}

function power(hase, exponent)
{
	var result = 1;
	for(var i = 0; i<exponent; i++)
	{
		result *= base;
	}
	return result;
}

function between(string, start, end)
{
	var startAt = string.indexOf(start);
	if(startAt == -1)
		return undefined;
	startAt += start.length;
	var endAt = string.indexOf(end, startAt);
	if(endAt == -1)
		return undefined;	
	return string.slice(startAt, endAt);
}
